import {ElMessage, ElMessageBox} from "element-plus/es";
import {ElNotification} from 'element-plus'

class MsgUtils {
    public successMsg(message: string) {
        ElMessage({message: message, type: 'success', showClose: true})
    }

    public warningMsg(message: string) {
        ElMessage({message: message, type: 'warning', showClose: true})
    }

    public infoMsg(message: string) {
        ElMessage({message: message, type: 'info', showClose: true})
    }
    public errorMsg(message: string) {
        ElMessage({message: message, type: "error", showClose: true});
    }


    public errorNotify(message: string, title?: string) {
        if (title == undefined) {
            title = '发生错误';
        }
        ElNotification({message: message, title: title, type: "error", duration: 0, showClose: true})
    }

    public  confirm(doing:()=>any, msg: string, title?: string, type?: 'success' | 'warning' | 'info' | 'error') {
        let confirm = true;
        ElMessageBox.confirm(msg, title? title : '确认操作', {
            confirmButtonText: '确认', cancelButtonText: '取消', type: type ? type : 'info',
        }).then((res) => {
            if ((res === 'confirm')) {
                doing();
            }
        }).catch(reason => {
        });
    }
}

export default new MsgUtils();